#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    string minWindow(string s, string t) {
        int hash1[128] = { 0 }, hash2[128] = { 0 };
        int sum = 0;
        for (auto& e : t) {
            if (hash1[e]++ == 0) sum++;
        }
        int min_len = INT_MAX, begin = -1;
        for (int left = 0, right = 0, count = 0; right < s.size(); right++) {
            char in = s[right];
            hash2[in]++;
            if (hash1[in] == hash2[in]) count++;
            while (count == sum) {
                if (right - left + 1 < min_len) {
                    begin = left;
                    min_len = right - left + 1;
                }
                char out = s[left++];
                if (hash1[out] == hash2[out]) count--;
                hash2[out]--;
            }
        }
        if (begin == -1) return "";
        else return s.substr(begin, min_len);
    }
};